// 首页
// http://180.188.35.36:88/h5/

// 登录
// http://180.188.35.36:88/h5/#/pages/login/login

// 接单
// http://180.188.35.36:88/index.php/User/Task/ceshi


function openHome() {
    let token = Android.getMap("token")
    if (!token) {
        return
    }
    let l = token.split(",")
    localStorage.setItem("userid", l[0])
    localStorage.setItem("username", l[1])
}
openHome()


// 获取toke
function getAndroidToken() {
    let userid = localStorage.getItem("userid")
    let username =  localStorage.getItem("username")
    return userid + "," + username
}
getAndroidToken()



// 接单
function getParameterHandler() {
    let token = parameter.getMap("token")
    if (!token) {
        return
    }
    let l = token.split(",")
    let headers = {}
    let body = {
        "username": l[1],
        "userid": l[0]
    }
    let strUrl = ``
    let url = parameter.getMap("url") + strUrl
    return {
        mediaType: "form",
        requestType: "POST",
        url: url,
        headers: JSON.stringify(headers),
        body: JSON.stringify(body)
    }
}
getParameterHandler()



// 处理返回数据
function getResponse() {
    let res = response.getMap("res")
    res = JSON.parse(res)

    let code = "500"
    let message = res["msg"]
    if (res["status"] == 0) {
        code = "200"
    } else if (res["status"] == 1) {
        code = "500"
    } else {
        code = "300"
    }
    let decodedStr = message.replace(/\\u([\d\w]{4})/gi, (match, p1) =>
        String.fromCharCode(parseInt(p1, 16))
    );
    return {
        code: code,
        message: decodedStr,
        dataKey: "",
        dataValue: ""
    }
}
getResponse()


// {
// 	"status": 1,
// 	"data": "抱歉，暂无订单1。",
// 	"msg": "抱歉，暂无订单1。"
// }

// {
// 	"msg": "您的身份信息不符合接单标准！"
// }